<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\SetMealSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '套餐列表';
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="set-meal-index col-sm-12" style="margin-top: 15px;">
    <p>
        <?= Html::a("创建套餐", ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <div class="ibox ibox-content">
        <?php echo $this->render('_search', ['model' => $searchModel]); ?>


        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'tableOptions' => ['class' => 'table table-striped'],
//            'options' => ['class' => 'grid-view', 'style' => 'overflow:auto', 'id' => 'grid'],
            //'filterModel' => $searchModel,
            'columns' => [
                'id',
                "title",
                [
                    'headerOptions' => ['width'=>'200px'],
                    'attribute' => 'images',
                    'value' => function ($m) {
                        return array_column($m->setMealImages, "img");
                    },
                    'class' => kn\images\ViewImages::class,
                ],
                'am_stock',
                'pm_stock',
                [
                    'attribute' => 'updated_at',
                    'value' => function ($m) {
                        return date('Y-m-d H:i:s', $m->updated_at);
                    }
                ],
                [
                    'class' => 'yii\grid\ActionColumn',
                    'header' => '操作',
                    'headerOptions' => ['width' => '150px'],
                    'template' => '{update} {delete}',
                    'buttons' => [
                        'update' => function ($url, $model, $key) {
                            return Html::a('修改', $url, ['class' => 'btn btn-outline btn-info btn-xs']);
                        },
                        'delete' => function ($url, $model, $key) {
                            return Html::a('删除', $url, ['data-confirm' => '你确定要删除吗?', 'data-method' => 'POST', 'class' => 'btn btn-outline btn-danger btn-xs']);
                        }
                    ],
                ],
            ],
        ]); ?>
    </div>
</div>
